
import apis from '../../http/apis/apis.js';
export default {
    //避免命名冲突
    namespaced: true,
    state: {
        //车位数组
        total: 0,
        pages: 0,
        pageSize: "",
        currentPage: 1,
        parkings: [],
        form: {
            num: '',
            day: '',
            price: '',
            desc: '',
            property: ""
        },
        editcarPort: {
            address: "",
            number: "",
            cycle: "",
            price: "",
        },
        lessorsId: ''
    },
    mutations: {
        //修改车位数据
        changeParkingsData(state, data) {
            state.parkings = data.parkings;
            state.total = data.total;
            state.pages = data.pages;
        },
        //改变显示条数
        changePageSize(state, pageSize) {
            state.pageSize = pageSize;
        },
        //改变当前页
        changeCurrentPage(state, currentPage) {
            state.currentPage = currentPage
        },
        changeLessorsId(state, newData) {
            state.lessorsId = newData
        },
        //修改数据渲染
        changeData(state, data) {
            console.log(123, data);
            state.editcarPort.address = data.address;
            state.editcarPort.number = data.number;
            state.editcarPort.cycle = data.cycle;
            state.editcarPort.price = data.price;
        }
    },
    actions: {
        //渲染页面
        async getParkingsById(context) {
            const { data } = await apis.parkingsById.getParkingsById({
                currentPage: context.state.currentPage,
                pageSize: context.state.pageSize,
                lessorsId: context.state.lessorsId
            });
            if (data.status) {
                context.commit('changeParkingsData', data.data);
            }
        },
        //增加车位
        async addParkings(context, _id) {
            const { data } = await apis.parkingsById.addParkings({
                // _id,
                property: context.state.form.property,
                address: context.state.form.desc,
                number: context.state.form.num,
                cycle: context.state.form.day,
                price: context.state.form.price,
                lessorsId: localStorage.userJudge.split(",")[0] 
            })
            console.log("新增", data);
            if (data.status) {

            }
        },
        //删除
        async deleteParkingsById(context, _id) {
            const { data } = await apis.parkingsById.deleteParkingsById({ _id });
            if (data.status) {
                alert(data.message);
                context.dispatch('getParkingsById')
            }
        },
        //修改
        async confirmChange(context, editcarPort, _id) {
            console.log("修改");
            const { data } = await apis.parkingsById.confirmChange(editcarPort, { _id })
            console.log(123, data);
        },
        //修改状态
        async updataAuditParkings(context, {_id,state}) {
            const { data } = await apis.parkings.updataAuditParkings({ _id ,state})
            console.log('data', data);
        }
    }
}